<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.css" rel="stylesheet" />
		<link href="../css/style.css?100" rel="stylesheet" />
		<script src="../js/flexible.js"></script>
		<script src="../js/flexible_css.js"></script>
		<script src="../js/axios-proxy.js"></script>
		<script src="../conf.js"></script>
		<script src="../js/api.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
	</head>
	<style>body{background-color: #fcfcfc;}</style>
	<body>
		<div class="login" id="app">
			<div class="login-from register-content">
				<div class="login-head">
					<div class="login-content">
						<h6>注册</h6>
						<div class="login-inpts" id="custom-nav">
							<input type="text" v-model="userInfo.phone" placeholder="手机号">
							<input type="text" v-model="userInfo.code" placeholder="验证码"><button class="btn-codes" @click="sendCode">{{sendmsg}}</button>
							 <input type="password" v-model="userInfo.password" placeholder="密码">
							 <input type="password" v-model="userInfo.passwordtwo" placeholder="确认密码">
							 <input type="text" v-model="userInfo.groomcode" placeholder="注册码">
							 <a class="login-inpts-forget" href="login.html">已有账号，去登录?</a>
						</div>
					</div>
				</div>
			</div>
			<div class="login-btns"><button @click="registered">注册</button></div>
		</div>
		<script src="../js/mui.js"></script>
		<script type="text/javascript">
			mui.init();
			mui('#custom-nav').on('tap', 'a', function() {
				var href = this.getAttribute('href');
				openwind(href);
			});
		let vm = new Vue({
				el: "#app",
				data: {
					userInfo: {
						code: "",
						password: "",
						phone: "",
						groomcode: "",
						passwordtwo:"",
						groomcode:''
					},
					sendmsg: '发送',
					trueCode: null
				},
				methods: {
					sendCode: function(){
						if (!checkPhone(this.userInfo.phone)) {
							smallPopup('请输入正确的手机号码')
							return
						}
						let timeCode,_num = 60;
						clearInterval(timeCode);
						getmessage({
							phone: this.userInfo.phone
						},function(res){
							vm.trueCode = res.data;
							timeCode = setInterval(function(){
								_num --;
								vm.sendmsg = _num + '秒';
								if (_num <= 0) {
									vm.sendmsg = '重新发送';
									_num = 60;
									clearInterval(timeCode)
								}
							}, 1000)
						})
					},
					registered: function() {
						if (!checkPhone(this.userInfo.phone)) {
							smallPopup('请输入正确的手机号码')
							return
						}
						if(this.userInfo.code != this.trueCode) {
							smallPopup('验证码输入错误，请重新输入')
							return
						}
						if(this.userInfo.password !== '' || this.userInfo.passwordtwo !== ''){
							if(this.userInfo.password !== this.userInfo.passwordtwo){
								smallPopup('俩次密码不一致请重新输入')
								return
							}
						} else {
							smallPopup('请输入密码')
							return
						}
						register(this.userInfo, function(res) {
								vm.codemsg = res;
								if (res.result === 0){
									mui.alert('账号已注册');
								}else if (res.result === 1){
									plus.nativeUI.toast("注册成功,请登录~");
									openwind('login.html');
								}
						})
					}
				}
			});
		</script>
	</body>
</html>
